/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.pdx.cs.guavadata.domain;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import java.lang.String;
import java.sql.ResultSet;
import java.util.UUID;

/**
 *
 * @author VuTran
 */
public class UniqueIdentifier extends Domain {

    @Override
    public boolean validate(Object o) {
        if (o == null) return true;
        if (o instanceof UUID) return true;
        return false;
    }

    @Override
    public Object convertString(String s) throws DomainConversionException {
        try {
            return UUID.fromString(s);
        } catch (IllegalArgumentException ie) {
            throw new DomainConversionException(ie.getMessage(), ie);
        }
    }

    @Override
    public Class getNaiveType() {
        return UUID.class;
    }

    @Override
    public String getDBType() {
        return "uniqueidentifier";
    }

    @Override
    public boolean equals(Object obj) {
        return (obj instanceof UniqueIdentifier);
    }

    @Override
    public int hashCode() {
        return UUID.class.hashCode();
    }

    @Override
    public String toString() {
        return "UniqueIdentifier";
    }

    @Override
    public Domain upcast() {
        return null;
    }

    @Override
    public Object upcastValue(Object o) throws Exception {
        return null;
    }

    @Override
    public Domain merge(Domain d) {
        if (d instanceof UniqueIdentifier) return this;
        return null;
    }

    @Override
    public boolean isOrdered() {
        return false;
    }

    @Override
    public boolean canContain() {
        return false;
    }

    @Override
    public Domain clone() {
        return new UniqueIdentifier();
    }

    @Override
    public Element ToXml(Document xdoc) {
        Element xe = xdoc.createElement("Domain");
        xe.setAttribute("Type", "UniqueIdentifier");
        return xe;
    }

    public static UniqueIdentifier fromElement(Element e) {
        return new UniqueIdentifier();
    }
    
    public static UniqueIdentifier FromDBInfoRow(ResultSet dr) {
        UniqueIdentifier o = new UniqueIdentifier();
        return o;
    }

}
